home *** CD-ROM | disk | FTP | other *** search
/ CD Ware Multimedia 1994 November / Cd Ware (Nro. 2) - Epimundo.iso / DOS / PG / DBPP20.ZIP / DBPPDATA.HPP < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-12  |  7.9 KB  |  132 lines

  1. /*
  2.    Library: DataBase++ Ver. 2.00.
  3.    File:    DBPPDATA.HPP
  4.    Purpose: Declarations for class DBDatabase. Code in DBPPDATA.cpp
  5.    Notice:  Copyright (C), 1992 - 1994, Jeff Stapleton. All rights reserved.
  6. */
  7.  
  8. /* Declaratons for the DBDatabase class.
  9. */
  10.  
  11. #ifndef __DBPPDATA_HPP
  12. #define __DBPPDATA_HPP
  13.  
  14. #include <dbppobjt.hpp>    // DBObject class.
  15. #include <dbppstru.hpp>    // DBStructure class.
  16. #include <dbppindx.hpp>    // DBIndex class.
  17. #include <dbpparay.hpp>    // DBArray class.
  18. #include <stdio.h>
  19.  
  20. extern "C" {
  21. #include <d4all.h>         // CodeBase
  22. }
  23.  
  24. class DBDatabase;
  25.  
  26. typedef BOOL ( * FilterFunc ) ( DBDatabase &dbf );      // Filter function pointer.
  27.  
  28. /* DBDatabase class using the CodeBase 5.0 library.
  29. */
  30. class DBDatabase : public DBObject
  31. {
  32.    public:
  33.  
  34.       /* Constructors and Destructor.
  35.       */
  36.       DBDatabase();                                        // Make a new DBDatabase.
  37.       DBDatabase( char * fName );                          // Make a new DBDatabase, with it's file name.
  38.       virtual ~DBDatabase();                               // Destroy it.
  39.       
  40.       /* Class methods.
  41.       */
  42.       static CODE4 *     CodeBase() { return &codeBase; }   // Return a pointer to the CODE4 struct.
  43.       static char *      GetCentury() { return century; }   // Return the century.
  44.       static int         Instances() { return instances; }  // Number of instances of self.
  45.       static void        Initialize();
  46.       static void        Shutdown();
  47.       static int         OpenFiles() { return openFiles; }  // Number of open files.
  48.       static void        SetCentury( char *aCentury ) { strcpy( century, aCentury ); }      // Set century.
  49.       static void        SetMultiUser( BOOL state );        // set multi user.
  50.       static BOOL        SetSafety( BOOL flag );            // Set safety.
  51.       static void        CloseAll();                        // Close all open files.
  52.  
  53.       /* Instance methods.
  54.       */
  55.       BOOL        append();                                 // Append a blank record.
  56.       BOOL        appendBlank() { return append(); }        // Append a blank record.
  57.       BOOL        bof() { return d4bof( Data4 ); }         // TRUE if bof.
  58.       BOOL        close();                                  // Close the opened file.
  59.       BOOL        create( DBStructure& dbs );                 // Create a database.
  60.       BOOL        create( DBStructure& dbs, DBIndexTag& idx );  // Create a database and index.
  61.       BOOL        createIndex( DBIndexTag& idx );             // Create an index file.
  62.       void        deleteRec() { d4delete( Data4 ); }       // Delete a record.
  63.       BOOL        deleted() { return d4deleted( Data4 ); } // Return's TRUE if deleted.
  64.       BOOL        eof() { return d4eof( Data4 ); }         // TRUE if eof.
  65.       int         fieldNum( char *fldName ) { return( d4field_number( Data4, fldName ) ); }                // Return position of the field fldName.
  66.       int         fieldType( char *fldName );               // Return the field type.
  67.       BOOL        fileLock() { return( ( d4lock_file( Data4 ) ) == 0 ); }                              // Lock file. Return's 1 if successful.
  68.       char *      fileName() { return FileName; }           // Return the file name.
  69.       DATA4 *     getDATA4() const { return Data4; }      // Return pointer to Data4.
  70.       char *      getDate( char *fldName );                 // Return a date field.
  71.       double      getDouble( char *fldName );               // Return a double field.
  72.       int         getInt( char *fldName );                  // Return an int.
  73.       int         getLogical( char *fldName );              // Return TRUE if true. 
  74.       long        getLong( char *fldName );                 // Return a long field.
  75.       char *      getMemo( char *fldName );                 // Return a memo.
  76.       char *      getString( char *fldName );               // Return a string field.
  77.       void        go( long nRecno );                        // Go to a record number.
  78.       void        goBottom();                               // Go to eof.
  79.       void        goTop();                                  // Go to bof.
  80.       char *      indexTag();                               // Return's name of current index tag.
  81.       BOOL        isOpen() { return openState; }            // TRUE if open.
  82.       void        memoPack();                               // Pack the memo file.
  83.       int         numFields() { return( d4num_fields( Data4 ) ); }                              // Return's number of fields in DBDatabase.
  84.       BOOL        open();                                   // Open the file.
  85.       #if !defined( S4FOX ) && !defined( INDEX_GROUPS )
  86.       BOOL        openIndex( char * indexFile );            // Open an index file.
  87.       #endif
  88.       void        pack( int mPack = 0 );                    // Pack the file. If mPack is TRUE, the associated memo file is also packed.
  89.       long        reccount() { return d4reccount( Data4 ); }                               // Return number of records.
  90.       void        recall() { d4recall( Data4 ); }          // Recall a deleted record.
  91.       void        reindex();                                // Reindex the file.
  92.       BOOL        recLock() { return( ( d4lock( Data4, recno() ) ) == 0 ); }                                // Lock current record. Return's 1 if successful.
  93.       long        recno() { return d4recno( Data4 ); }                                  // Return record number.
  94.       void        replace( char *fldName, char *str );      // Character, memo and date.
  95.       void        replace( char *fldName, double d );       // double
  96.       void        replace( char *fldName, int i );          // int's and logical
  97.       void        replace( char *fldName, long l );         // long.
  98.       int         seek( char *seekExpr );                   // Seek an index for seekExpr.
  99.       void        setFileName( char * fName );              // Set the FileName.
  100.       void        setFilter( FilterFunc ff ) { pFilterFunc = ff; }   // Set a filter function.
  101.       BOOL        setIndexTag( char *aTagName = NULL );     // Select an index tag.
  102.       void        skip( int nRecs = 1 );                    // Skip record(s) nRecs.
  103.       void        unlock() { d4unlock( Data4 ); }             // Release all locks.
  104.       int         unlockIndex();                            // Unlock current index if any.
  105.       void        zap( int mPack = 0 );                     // Zap the file. If mPack is TRUE, the associated memo file is also packed.
  106.       
  107.    private:
  108.  
  109.       /* Class variables.
  110.       */
  111.       static CODE4   codeBase;                              // Code Base struct.
  112.       static int     openFiles;                             // Number of open files.
  113.       static int     instances;                             // Number of DBDatabase objects.
  114.       static char    century[ 3 ];                          // Hold's century chars.
  115.       static BOOL    safety;                                // FALSE if create overwrites, TRUE if warning. Set to FALSE.
  116.       static BOOL    multiUser;                             // TRUE if multi user, otherwise FALSE;
  117.          
  118.       /* Instance vars.                                     
  119.       */                                                    
  120.       char        FileName [ 80 ];                          // Name of the file.
  121.       DATA4 *     Data4;                                    // Pointer to data structure.
  122.       BOOL        openState;                                // TRUE if open; FALSE if closed.
  123.       FilterFunc  pFilterFunc;                              // Pointer to a user supplied filter function.
  124.          
  125.       /* Private methods                                    
  126.       */                                                    
  127.       void        init();                                   // Initialize this.
  128.       void        removeFromArray();                        // Remove this from array.
  129. };
  130.  
  131. #endif // _DBPPDATA_HPP
  132.